package cn.edu.xmist.proxy.dynamicproxy;

import cn.edu.xmist.proxy.Hello;
import cn.edu.xmist.proxy.Hello2;
import cn.edu.xmist.proxy.Hello2Impl;
import cn.edu.xmist.proxy.HelloImpl;

import java.lang.reflect.Proxy;

public class DynamicProxyTest {
    public static void main(String[] args) {
        HelloImpl hello = new HelloImpl();
        DynamicProxy dynamicProxy = new DynamicProxy(hello);
        Hello proxy = (Hello) Proxy.newProxyInstance(hello.getClass().getClassLoader(), hello.getClass().getInterfaces(), dynamicProxy);
        proxy.say("lisi");

        Hello2Impl hello2 = new Hello2Impl();
        DynamicProxy dynamicProxy2 = new DynamicProxy(hello2);
        Hello2 proxy2 = (Hello2) Proxy.newProxyInstance(hello2.getClass().getClassLoader(), hello2.getClass().getInterfaces(), dynamicProxy2);
        proxy2.doSomething();
    }
}
